package com.cyw.search.controller;

import cn.easyes.core.biz.PageInfo;
import com.cyw.common.core.controller.BaseController;
import com.cyw.common.core.domain.R;
import com.cyw.search.entity.videos.Videos;
import com.cyw.search.service.VideosService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Author: 二叔
 * @Date: 2022/11/10/22:37
 */
@RestController
@RequestMapping("search/videos")
@Api(value = "短视频接口", tags = {"短视频接口"})
public class EsShortVideoController extends BaseController {

    @Resource
    private VideosService videosService;

    @ApiOperation("发布短视频")
    @PostMapping("publishVideo")
    public R publishVideo(@ApiParam("经纬度字符串->(纬,经)") @RequestParam("geoPoint") String geoPoint,
                            @ApiParam("内容") @RequestParam("content") String content,
                            @ApiParam("短视频") @RequestPart("file") MultipartFile multipartFile) {
        return videosService.publishVideo(geoPoint,content,multipartFile);
    }

    @ApiOperation("查看附近短视频")
    @GetMapping("searchNearVideos")
    public R<PageInfo<Videos>> searchNearVideos(@ApiParam("经纬度字符串->(纬,经)") @RequestParam("geoPoint") String geoPoint,
                                                @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(videosService.searchNearVideos(geoPoint,pageNum,pageSize));
    }

    @ApiOperation("查看推荐短视频")
    @GetMapping("searchRecommendVideos")
    public R<PageInfo<Videos>> searchRecommendVideos(@ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                     @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(videosService.searchRecommendVideos(pageNum,pageSize));
    }

    @ApiOperation("查看我关注用户的短视频")
    @GetMapping("searchMyFollowVideos")
    public R<PageInfo<Videos>> searchMyFollowVideos(@ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                    @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(videosService.searchMyFollowVideos(pageNum,pageSize));
    }

    @ApiOperation("短视频点爱心/取消爱心")
    @GetMapping("loveOrUnLove")
    public R loveOrUnLove(@ApiParam("短视频id") @RequestParam("videoId") Long videoId){
        return R.ok(videosService.loveOrUnLove(videoId));
    }

    @ApiOperation("删除短视频")
    @DeleteMapping("deleteVideo/{videoId}")
    public R deleteMoments(@PathVariable("videoId") Long videoId){
        return R.ok(videosService.deleteVideo(videoId));
    }
}
